********************************************************************************
* Terrorist Violence and the Fuzzy Frontier: 
* National and Supranational Identities in Britain
*
* The Journal of Law, Economics, and Organization
*
* By Georgios Efthyvoulou, Harry Pickard and Vincenzo Bove
*
********************************************************************************

clear all

if "`c(username)'"=="nhp7115" {
	if "`c(machine_type)'"=="Mac (Apple Silicon)" {
		glo project "/Users/nhp7115/Dropbox/Immigration, Terrorism & Voting/BES-Britishness/code & data/JLEO replication files/replication_files"
	}
	else {
		glo project "C:/Users/nhp7115/Dropbox/Immigration, Terrorism & Voting/BES-Britishness/code & data/JLEO replication files/replication_files"
	}	
	
	cap mkdir "$project/output_main"
	glo output "$project/output_main"
	glo controls "female age age2 i.work_clean i.education_clean i.marital_clean i.ethnicity_clean p_hh_size p_gross_household"
}

********************************************************************************

// Load the dataset
use "$project/dataset.dta", clear



********************************************************************************
**** Table 1: Summary statistics of key variables
********************************************************************************


est clear 
estpost sum britishness5 britishness nationness5 nationness euintegration7 euintegration effectseuterror3 effectseuterror time_prox_ld time_dist geo_prox_std geo_dist if sample1
esttab using "$output/Table_1.csv", cells("mean(fmt(%8.3f)) sd(fmt(%8.3f)) min(fmt(%8.3f)) max(fmt(%8.3f)) count(fmt(%8.0f)) blank()") nonumbers noobs wide ///
collabels("Mean" "Std. Dev." "Min." "Max." "Obs." "Definition") ///
varl( ///
britishness5 "Britishness (DV)" britishness "Britishness (cont.)" nationness5 "Nationness (DV)" nationness "Nationness (cont.)" euintegration7 "Pro-EU sentiment (DV)" euintegration "Pro-EU sentiment (cont.)" effectseuterror3 "Risk perceptions (DV)" effectseuterror "Risk perceptions (cont.)" geo_prox_std "Exposure" geo_dist "Geographic distance (KMs)" time_prox_ld "Time prox." time_dist "Temporal distance (days)") ///
replace csv
		




********************************************************************************
*** Table 2: Terrorism exposure and identity: Main results
********************************************************************************

est clear
foreach y in britishness nationness {
	
	if "`y'"=="britishness" {
		loc opt "replace"
	} 
	else {
		loc opt "append"
	}
	
eststo: reghdfe `y'5 c.geo_prox_std##c.time_prox_ld if sample1==1, absorb(id attack_code, save) vce(cluster id)
		estadd local individual "X", replace	
		estadd local attack "X", replace
		estadd local ww "", replace
		estadd local controls "", replace
		
eststo: reghdfe `y'5 c.geo_prox_std##c.time_prox_ld if sample1==1, absorb(id attack_code wave##week_fe, save) vce(cluster id)
		estadd local individual "X", replace	
		estadd local attack "X", replace
		estadd local ww "X", replace
		estadd local controls "", replace
		
eststo: reghdfe `y'5 c.geo_prox_std##c.time_prox_ld $controls if sample1==1, absorb(id attack_code wave##week_fe, save) vce(cluster id)
		estadd local individual "X", replace	
		estadd local attack "X", replace
		estadd local ww "X", replace
		estadd local controls "X", replace

		
eststo: reghdfe `y' c.geo_prox_std##c.time_prox_ld if sample1==1, absorb(id attack_code, save) vce(cluster id)
		estadd local individual "X", replace	
		estadd local attack "X", replace
		estadd local ww "", replace
		estadd local controls "", replace
		
eststo: reghdfe `y' c.geo_prox_std##c.time_prox_ld if sample1==1, absorb(id attack_code wave##week_fe, save) vce(cluster id)
		estadd local individual "X", replace	
		estadd local attack "X", replace
		estadd local ww "X", replace
		estadd local controls "", replace
		
eststo: reghdfe `y' c.geo_prox_std##c.time_prox_ld $controls if sample1==1, absorb(id attack_code wave##week_fe, save) vce(cluster id)
		estadd local individual "X", replace	
		estadd local attack "X", replace
		estadd local ww "X", replace
		estadd local controls "X", replace		
		
esttab est* using "$output/Table_2.csv", star(* .1 ** .05 *** .01) se b(3) r2 ///
keep(geo_prox_std time_prox_ld c.geo_prox_std#c.time_prox_ld) ///
order(geo_prox_std time_prox_ld c.geo_prox_std#c.time_prox_ld) ///
varl(geo_prox_std "Exposure" time_prox_ld "Time prox." c.geo_prox_std#c.time_prox_ld "Exposure $\times$ Time prox.") ///
s(individual attack ww controls r2 N_clust N, ///
label("Individual FEs" "Attack FEs" "Wave $\times$ Week FEs" "Controls" "R-squared" "No. of individuals" "No. of observations" ) ///
fmt(3 3 3 3 %9.3f %9.0f %9.0f)) ///
`opt' csv nonotes
est clear
	
}







********************************************************************************
*** Figure 1: Relative identity
********************************************************************************

*** Figure (a): Britishness

est clear		
forv i=1/3 {
eststo: reghdfe britishness5 c.geo_prox_std##c.time_prox_ld $controls if dif_identity_cat==`i' & sample1==1, absorb(id attack_code wave##week_fe, save) vce(cluster id)
lincomest geo_prox_std + c.geo_prox_std#c.time_prox_ld, eform(OR)
est save int`i', replace
estimates use int`i'
estimates store int`i'
}	
	coefplot ///
	(int1, msymbol(circle) rename( (1) = "Stronger Britishness") mcolor(black) ciopts(lcolor(black black))) ///
	(int2, msymbol(circle) rename( (1) = "Equally Strong") mcolor(black) ciopts(lcolor(black black))) ///
	(int3, msymbol(circle) rename( (1) = "Stronger Nationness") mcolor(black) ciopts(lcolor(black black))) ///
	, levels(95 90) xtitle("Estimate at Max. Time Proximity", size(Large)) ytitle("", size(Large)) legend(off) ///
	title("The Effect of Exposure on Britishness (DV)", color(black) size(Medium)) ///
	xline(0, lcolor(black) lwidth(medthick) lpattern(dash)) ///
	xscale(range(-0.050(0.010)0.050)) xlabel(-0.050(0.010)0.050) ///
	scheme(s1color) graphregion(color(white)) bgcolor(white) ///
	recast(connected) lc(black) mc(black) ciopts(recast(rcap) lc(black)) ///
	name("fig_a", replace)
	*graph export "$output/Figure_RelativeID_Britishness_DV.pdf", as(pdf) replace
	
forv i=1/3 {
erase int`i'.ster
}

***

est clear		
forv i=1/3 {
eststo: reghdfe britishness c.geo_prox_std##c.time_prox_ld $controls if dif_identity_cat==`i' & sample1==1, absorb(id attack_code wave##week_fe, save) vce(cluster id)
lincomest geo_prox_std + c.geo_prox_std#c.time_prox_ld, eform(OR)
est save int`i', replace
estimates use int`i'
estimates store int`i'
}	
	coefplot ///
	(int1, msymbol(circle) rename( (1) = "Stronger Britishness") mcolor(black) ciopts(lcolor(black black))) ///
	(int2, msymbol(circle) rename( (1) = "Equally Strong") mcolor(black) ciopts(lcolor(black black))) ///
	(int3, msymbol(circle) rename( (1) = "Stronger Nationness") mcolor(black) ciopts(lcolor(black black))) ///
	, levels(95 90) xtitle("Estimate at Max. Time Proximity", size(Large)) ytitle("", size(Large)) legend(off) ///
	title("The Effect of Exposure on Britishness (cont.)", color(black) size(Medium)) ///
	xline(0, lcolor(black) lwidth(medthick) lpattern(dash)) ///
	xscale(range(-0.050(0.010)0.050)) xlabel(-0.050(0.010)0.050) ///
	scheme(s1color) graphregion(color(white)) bgcolor(white) ///
	recast(connected) lc(black) mc(black) ciopts(recast(rcap) lc(black)) ///
	name("fig_b", replace)
	*graph export "$output/Figure_RelativeID_Britishness_Cont.pdf", as(pdf) replace
	
forv i=1/3 {
erase int`i'.ster
}

*** Figure (b): Nationness

est clear		
forv i=1/3 {
eststo: reghdfe nationness5 c.geo_prox_std##c.time_prox_ld $controls if dif_identity_cat==`i' & sample1==1, absorb(id attack_code wave##week_fe, save) vce(cluster id)
lincomest geo_prox_std + c.geo_prox_std#c.time_prox_ld, eform(OR)
est save int`i', replace
estimates use int`i'
estimates store int`i'
}	
	coefplot ///
	(int1, msymbol(circle) rename( (1) = "Stronger Britishness") mcolor(black) ciopts(lcolor(black black))) ///
	(int2, msymbol(circle) rename( (1) = "Equally Strong") mcolor(black) ciopts(lcolor(black black))) ///
	(int3, msymbol(circle) rename( (1) = "Stronger Nationness") mcolor(black) ciopts(lcolor(black black))) ///
	, levels(95 90) xtitle("Estimate at Max. Time Proximity", size(Large)) ytitle("", size(Large)) legend(off) ///
	title("The Effect of Exposure on Nationness (DV)", color(black) size(Medium)) ///
	xline(0, lcolor(black) lwidth(medthick) lpattern(dash)) ///
	xscale(range(-0.050(0.010)0.050)) xlabel(-0.050(0.010)0.050) ///
	scheme(s1color) graphregion(color(white)) bgcolor(white) ///
	recast(connected) lc(black) mc(black) ciopts(recast(rcap) lc(black)) ///
	name("fig_c", replace)
	*graph export "$output/Figure_RelativeID_Nationness_DV.pdf", as(pdf) replace
	
forv i=1/3 {
erase int`i'.ster
}

***

est clear		
forv i=1/3 {
eststo: reghdfe nationness c.geo_prox_std##c.time_prox_ld $controls if dif_identity_cat==`i' & sample1==1, absorb(id attack_code wave##week_fe, save) vce(cluster id)
lincomest geo_prox_std + c.geo_prox_std#c.time_prox_ld, eform(OR)
est save int`i', replace
estimates use int`i'
estimates store int`i'
}	
	coefplot ///
	(int1, msymbol(circle) rename( (1) = "Stronger Britishness") mcolor(black) ciopts(lcolor(black black))) ///
	(int2, msymbol(circle) rename( (1) = "Equally Strong") mcolor(black) ciopts(lcolor(black black))) ///
	(int3, msymbol(circle) rename( (1) = "Stronger Nationness") mcolor(black) ciopts(lcolor(black black))) ///
	, levels(95 90) xtitle("Estimate at Max. Time Proximity", size(Large)) ytitle("", size(Large)) legend(off) ///
	title("The Effect of Exposure on Nationness (cont.)", color(black) size(Medium)) ///
	xline(0, lcolor(black) lwidth(medthick) lpattern(dash)) ///
	xscale(range(-0.050(0.010)0.050)) xlabel(-0.050(0.010)0.050) ///
	scheme(s1color) graphregion(color(white)) bgcolor(white) ///
	recast(connected) lc(black) mc(black) ciopts(recast(rcap) lc(black)) ///
	name("fig_d", replace)
	*graph export "$output/Figure_RelativeID_Nationness_Cont.pdf", as(pdf) replace
	
forv i=1/3 {
erase int`i'.ster
}




gr combine fig_a fig_b fig_c fig_d, row(2) col(2) l1("Relative Identity") xsize(8)
gr export "$output/Figure_1.pdf", as(pdf) replace
gr export "$output/Figure_1.eps", as(eps) replace








********************************************************************************
**** Figure 2: Marginal effects of exposure on Britishness
********************************************************************************

quietly{

reghdfe britishness5 c.geo_prox_std##c.time_prox_ld $controls if sample1==1, absorb(id attack_code wave##week_fe, save) vce(cluster id)
margins, dydx(geo_prox_std) at(time_prox_ld=(0(.05)1)) noestimcheck
marginsplot, legend(pos(6) row(1)) yline(0, lcolor(black) lwidth(medthick) lpattern(dash)) ///
title("") xtitle("Time Proximity", height(5)) ytitle("Marginal Effect of Exposure on Britishness (DV)", size(medsmall)) yscale(titlegap(*+10)) ///
addplot(histogram time_prox_ld if e(sample), start(0) width(.1) legend(off) below fcolor(none) lcolor(gs10) ///
yaxis(2) yscale(off axis(2)) yscale(range(-0.010 0.030) axis(1)) ylabel(-0.010(.005).030, nogrid axis(1)) ///
scheme(s1color) graphregion(color(white)) bgcolor(white) ///
xlabel(-0(.1)1, nogrid)) ///
plot1opts(msize(medsmall) mcolor(black) lcolor(black)) ci1opts(lwidth(medium) lcolor(black)) ///
scheme(s1color) name(Fig_time_prox_ld_DV, replace)


reghdfe britishness c.geo_prox_std##c.time_prox_ld $controls if sample1==1, absorb(id attack_code wave##week_fe, save) vce(cluster id)
margins, dydx(geo_prox_std) at(time_prox_ld=(0(.05)1)) noestimcheck
marginsplot, legend(pos(6) row(1)) yline(0, lcolor(black) lwidth(medthick) lpattern(dash)) ///
title("") xtitle("Time Proximity", height(5)) ytitle("Marginal Effect of Exposure on Britishness (cont.)", size(medsmall)) yscale(titlegap(*+10)) ///
addplot(histogram time_prox_ld if e(sample), start(0) width(.1) legend(off) below fcolor(none) lcolor(gs10) ///
yaxis(2) yscale(off axis(2)) yscale(range(-0.010 0.030) axis(1)) ylabel(-0.010(.005).030, nogrid axis(1)) ///
scheme(s1color) graphregion(color(white)) bgcolor(white) ///
xlabel(-0(.1)1, nogrid)) ///
plot1opts(msize(medsmall) mcolor(black) lcolor(black)) ci1opts(lwidth(medium) lcolor(black)) ///
scheme(s1color) name(Fig_time_prox_ld_cont, replace)

}

graph combine Fig_time_prox_ld_DV Fig_time_prox_ld_cont
graph export "$output/Figure_2.pdf", replace
graph export "$output/Figure_2.eps", replace







********************************************************************************
*** Table 3: Terrorism exposure and Britishness: Binary time proximity
********************************************************************************


est clear
{		
eststo: reghdfe britishness5 c.geo_prox_std##c.time_prox_a2 if sample1==1, absorb(id attack_code, save) vce(cluster id)
		estadd local individual "X", replace	
		estadd local attack "X", replace
		estadd local ww "", replace
		estadd local controls "", replace
		
eststo: reghdfe britishness5 c.geo_prox_std##c.time_prox_a2 if sample1==1, absorb(id attack_code wave##week_fe, save) vce(cluster id)
		estadd local individual "X", replace	
		estadd local attack "X", replace
		estadd local ww "X", replace
		estadd local controls "", replace
		
eststo: reghdfe britishness5 c.geo_prox_std##c.time_prox_a2 $controls if sample1==1, absorb(id attack_code wave##week_fe, save) vce(cluster id)
		estadd local individual "X", replace	
		estadd local attack "X", replace
		estadd local ww "X", replace
		estadd local controls "X", replace

		

eststo: reghdfe britishness c.geo_prox_std##c.time_prox_a2 if sample1==1, absorb(id attack_code, save) vce(cluster id)
		estadd local individual "X", replace	
		estadd local attack "X", replace
		estadd local ww "", replace
		estadd local controls "", replace
		
eststo: reghdfe britishness c.geo_prox_std##c.time_prox_a2 if sample1==1, absorb(id attack_code wave##week_fe, save) vce(cluster id)
		estadd local individual "X", replace	
		estadd local attack "X", replace
		estadd local ww "X", replace
		estadd local controls "", replace
		
eststo: reghdfe britishness c.geo_prox_std##c.time_prox_a2 $controls if sample1==1, absorb(id attack_code wave##week_fe, save) vce(cluster id)
		estadd local individual "X", replace	
		estadd local attack "X", replace
		estadd local ww "X", replace
		estadd local controls "X", replace
		
	
esttab est* using "$output/Table_3.csv", star(* .1 ** .05 *** .01) se b(3) r2 ///
keep(geo_prox_std time_prox_a2 c.geo_prox_std#c.time_prox_a2) ///
order(geo_prox_std time_prox_a2 c.geo_prox_std#c.time_prox_a2) ///
varl(geo_prox_std "Exposure" time_prox_a2 "Time prox. (45-days)" c.geo_prox_std#c.time_prox_a2 "Exposure $\times$ Time prox. (45-days)") ///
s(individual attack ww controls r2 N_clust N, ///
label("Individual FEs" "Attack FEs" "Wave $\times$ Week FEs" "Controls" "R-squared" "No. of individuals" "No. of observations" ) /// 
fmt(3 3 3 3 %9.3f %9.0f %9.0f)) ///
replace csv nonotes
est clear
	
}







********************************************************************************
*** Figure 3: Marginal effect of exposure on Britishness: Binary time proximity
********************************************************************************

quietly{

reghdfe britishness5 c.geo_prox_std##c.time_prox_a2 $controls if sample1==1, absorb(id attack_code wave##week_fe, save) vce(cluster id)
margins, dydx(geo_prox_std) at(time_prox_a2=(0 1)) noestimcheck
marginsplot, legend(pos(6) row(1)) yline(0, lcolor(black) lwidth(medthick) lpattern(dash)) ///
title("") xtitle("Time Proximity (Days)", height(5)) ytitle("Marginal Effect of Exposure on Britishness (DV)", size(medsmall)) yscale(titlegap(*+10)) ///
xlabel(#2) xlabel(0 "46+" 1 "1-45", nogrid) ///
graphregion(color(white)) bgcolor(white) ///
addplot(histogram time_prox_a2 if e(sample), discrete yaxis(2) yscale(off axis(2)) yscale(range(-0.010 0.020) axis(1)) ylabel(-0.010(.005).020, nogrid axis(1))  legend(off) below fcolor(none) lcolor(gs10)) ///
plot1opts(msize(medsmall) mcolor(black) lcolor(black)) ci1opts(lwidth(medium) lcolor(black)) ///
scheme(s1color) name(Fig_time_prox_a2_DV, replace)


reghdfe britishness c.geo_prox_std##c.time_prox_a2 $controls if sample1==1, absorb(id attack_code wave##week_fe, save) vce(cluster id)
margins, dydx(geo_prox_std) at(time_prox_a2=(0 1)) noestimcheck
marginsplot, legend(pos(6) row(1)) yline(0, lcolor(black) lwidth(medthick) lpattern(dash)) ///
 title("") xtitle("Time Proximity (Days)", height(5)) ytitle("Marginal Effect of Exposure on Britishness (cont.)", size(medsmall)) yscale(titlegap(*+10)) ///
xlabel(#2) xlabel(0 "46+" 1 "1-45", nogrid) ///
graphregion(color(white)) bgcolor(white) ///
addplot(histogram time_prox_a2 if e(sample), discrete yaxis(2) yscale(off axis(2)) yscale(range(-0.010 0.020) axis(1)) ylabel(-0.010(.005).020, nogrid axis(1))  legend(off) below fcolor(none) lcolor(gs10)) ///
plot1opts(msize(medsmall) mcolor(black) lcolor(black)) ci1opts(lwidth(medium) lcolor(black)) ///
scheme(s1color) name(Fig_time_prox_a2_cont, replace)

}

graph combine Fig_time_prox_a2_DV Fig_time_prox_a2_cont
graph export "$output/Figure_3.pdf", replace
graph export "$output/Figure_3.eps", replace





********************************************************************************
**** Table 4: Terrorism exposure and Britishness: Placebo results
********************************************************************************

est clear
{
	
eststo: reghdfe britishness5 c.geo_prox_std##c.time_prox_ld $controls if sample3==1, absorb(id attack_code wave##week_fe, save) vce(cluster id)
		estadd local individual "X", replace	
		estadd local attack "X", replace
		estadd local ww "X", replace
		estadd local controls "X", replace
		
eststo: reghdfe britishness5 lag_britishness5 c.geo_prox_std##c.time_prox_ld $controls if sample3==1, absorb(id attack_code wave##week_fe, save) vce(cluster id)
		estadd local individual "X", replace	
		estadd local attack "X", replace
		estadd local ww "X", replace
		estadd local controls "X", replac
		
eststo: reghdfe lag_britishness5 c.geo_prox_std##c.time_prox_ld $controls if sample3==1, absorb(id attack_code wave##week_fe, save) vce(cluster id)
		estadd local individual "X", replace	
		estadd local attack "X", replace
		estadd local ww "X", replace
		estadd local controls "X", replace
	
		
eststo: reghdfe britishness c.geo_prox_std##c.time_prox_ld $controls if sample3==1, absorb(id attack_code wave##week_fe, save) vce(cluster id)
		estadd local individual "X", replace	
		estadd local attack "X", replace
		estadd local ww "X", replace
		estadd local controls "X", replace
		
eststo: reghdfe britishness lag_britishness c.geo_prox_std##c.time_prox_ld $controls if sample3==1, absorb(id attack_code wave##week_fe, save) vce(cluster id)
		estadd local individual "X", replace	
		estadd local attack "X", replace
		estadd local ww "X", replace
		estadd local controls "X", replac
				
eststo: reghdfe lag_britishness c.geo_prox_std##c.time_prox_ld $controls if sample3==1, absorb(id attack_code wave##week_fe, save) vce(cluster id)
		estadd local individual "X", replace	
		estadd local attack "X", replace
		estadd local ww "X", replace
		estadd local controls "X", replace
	
	
esttab est* using "$output/Table_4.csv", star(* .1 ** .05 *** .01) se b(3) r2 ///
keep(geo_prox_std time_prox_ld c.geo_prox_std#c.time_prox_ld lag_britishness5 lag_britishness) ///
order(geo_prox_std time_prox_ld c.geo_prox_std#c.time_prox_ld lag_britishness5 lag_britishness) ///
varl(geo_prox_std "Exposure" time_prox_ld "Time prox." c.geo_prox_std#c.time_prox_ld "Exposure $\times$ Time prox." lag_britishness5 "Britishness (DV){$_{w-1}$}" lag_britishness "Britishness (cont.){$_{w-1}$} ") ///
s(individual attack ww controls r2 N_clust N, ///
label("Individual FEs" "Attack FEs" "Wave $\times$ Week FEs" "Controls" "R-squared" "No. of individuals" "No. of observations" ) /// 
fmt(3 3 3 3 %9.3f %9.0f %9.0f)) ///
replace csv nonotes
est clear
	
}







********************************************************************************
**** Table 5: Terrorism exposure and EU attitudes
********************************************************************************

est clear
{		

// Panel A: EU integration	

eststo: reghdfe euintegration7 c.geo_prox_std##c.time_prox_ld if sample1==1, absorb(id attack_code, save) vce(cluster id)
		estadd local individual "X", replace	
		estadd local attack "X", replace
		estadd local ww "", replace
		estadd local controls "", replace
		
eststo: reghdfe euintegration7 c.geo_prox_std##c.time_prox_ld if sample1==1, absorb(id attack_code wave##week_fe, save) vce(cluster id)
		estadd local individual "X", replace	
		estadd local attack "X", replace
		estadd local ww "X", replace
		estadd local controls "", replace
		
eststo: reghdfe euintegration7 c.geo_prox_std##c.time_prox_ld $controls if sample1==1, absorb(id attack_code wave##week_fe, save) vce(cluster id)
		estadd local individual "X", replace	
		estadd local attack "X", replace
		estadd local ww "X", replace
		estadd local controls "X", replace
		
	
eststo: reghdfe euintegration c.geo_prox_std##c.time_prox_ld if sample1==1, absorb(id attack_code, save) vce(cluster id)
		estadd local individual "X", replace	
		estadd local attack "X", replace
		estadd local ww "", replace
		estadd local controls "", replace
		
eststo: reghdfe euintegration c.geo_prox_std##c.time_prox_ld if sample1==1, absorb(id attack_code wave##week_fe, save) vce(cluster id)
		estadd local individual "X", replace	
		estadd local attack "X", replace
		estadd local ww "X", replace
		estadd local controls "", replace
		
eststo: reghdfe euintegration c.geo_prox_std##c.time_prox_ld $controls if sample1==1, absorb(id attack_code wave##week_fe, save) vce(cluster id)
		estadd local individual "X", replace	
		estadd local attack "X", replace
		estadd local ww "X", replace
		estadd local controls "X", replace
		
esttab est* using "$output/Table_5.csv", star(* .1 ** .05 *** .01) se b(3) r2 ///
keep(geo_prox_std time_prox_ld c.geo_prox_std#c.time_prox_ld) ///
order(geo_prox_std time_prox_ld c.geo_prox_std#c.time_prox_ld) ///
varl(geo_prox_std "Exposure" time_prox_ld "Time prox." c.geo_prox_std#c.time_prox_ld "Exposure $\times$ Time prox.") ///
s(individual attack ww controls r2 N_clust N, ///
label("Individual FEs" "Attack FEs" "Wave $\times$ Week FEs" "Controls" "R-squared" "No. of individuals" "No. of observations" ) /// 
fmt(3 3 3 3 %9.3f %9.0f %9.0f)) ///
replace csv nonotes
est clear
		

// Panel B: Risk of terror outside the EU

eststo: reghdfe effectseuterror3 c.geo_prox_std##c.time_prox_ld if sample1==1, absorb(id attack_code, save) vce(cluster id)
		estadd local individual "X", replace	
		estadd local attack "X", replace
		estadd local ww "", replace
		estadd local controls "", replace
		
eststo: reghdfe effectseuterror3 c.geo_prox_std##c.time_prox_ld if sample1==1, absorb(id attack_code wave##week_fe, save) vce(cluster id)
		estadd local individual "X", replace	
		estadd local attack "X", replace
		estadd local ww "X", replace
		estadd local controls "", replace
		
eststo: reghdfe effectseuterror3 c.geo_prox_std##c.time_prox_ld $controls if sample1==1, absorb(id attack_code wave##week_fe, save) vce(cluster id)
		estadd local individual "X", replace	
		estadd local attack "X", replace
		estadd local ww "X", replace
		estadd local controls "X", replace

		
eststo: reghdfe effectseuterror c.geo_prox_std##c.time_prox_ld if sample1==1, absorb(id attack_code, save) vce(cluster id)
		estadd local individual "X", replace	
		estadd local attack "X", replace
		estadd local ww "", replace
		estadd local controls "", replace
		
eststo: reghdfe effectseuterror c.geo_prox_std##c.time_prox_ld if sample1==1, absorb(id attack_code wave##week_fe, save) vce(cluster id)
		estadd local individual "X", replace	
		estadd local attack "X", replace
		estadd local ww "X", replace
		estadd local controls "", replace
		
eststo: reghdfe effectseuterror c.geo_prox_std##c.time_prox_ld $controls if sample1==1, absorb(id attack_code wave##week_fe, save) vce(cluster id)
		estadd local individual "X", replace	
		estadd local attack "X", replace
		estadd local ww "X", replace
		estadd local controls "X", replace

esttab est* using "$output/Table_5.csv", star(* .1 ** .05 *** .01) se b(3) r2 ///
keep(geo_prox_std time_prox_ld c.geo_prox_std#c.time_prox_ld) ///
order(geo_prox_std time_prox_ld c.geo_prox_std#c.time_prox_ld) ///
varl(geo_prox_std "Exposure" time_prox_ld "Time prox." c.geo_prox_std#c.time_prox_ld "Exposure $\times$ Time prox.") ///
s(individual attack ww controls r2 N_clust N, ///
label("Individual FEs" "Attack FEs" "Wave $\times$ Week FEs" "Controls" "R-squared" "No. of individuals" "No. of observations" ) /// 
fmt(3 3 3 3 %9.3f %9.0f %9.0f)) ///
append csv nonotes
est clear

}









********************************************************************************
**** Figures 4 and 5: Marginal effect of exposure on Britishness: Heterogeneity by attack characteristics
********************************************************************************

**** Figure 4A: By number of victims

quietly{

reghdfe britishness5 c.geo_prox_std##c.time_prox_ld##i.victims_d1 $controls if sample1==1, absorb(id attack_code wave##week_fe, save) vce(cluster id)
margins , dydx(geo_prox_std) at(time_prox_ld=(0(.1)1) victims_d1=(0 1)) noestimcheck
marginsplot, legend(order(1 "Less than 2 victims" 2 "2 or more victims") pos(6) row(1)) legend(region(lstyle(none))) legend(symxsize(6) forcesize) legend(size(small)) title("Panel a", pos(12) size(medsmall)) yline(0, lcolor(black) lwidth(medthick) lpattern(dash)) ///
xtitle("Time Proximity", height(5)) ytitle("Marginal Effect of Exposure on Britishness (DV)", size(medsmall)) yscale(titlegap(*+10)) ///
xlabel(0(.1)1, nogrid) ylabel(-0.020(.010).050, nogrid) ///
plot1opts(msize(medsmall) mcolor(midblue) lcolor(midblue)) ci1opts(lwidth(medium) lcolor(midblue)) ///
plot2opts(msize(medsmall) mcolor(midgreen) lcolor(midgreen)) ci2opts(lwidth(medium) lcolor(midgreen)) ///
scheme(s1color) graphregion(color(white)) bgcolor(white) ///
name(Fig_time_prox_victims_DV, replace)
 
reghdfe britishness c.geo_prox_std##c.time_prox_ld##i.victims_d1 $controls if sample1==1, absorb(id attack_code wave##week_fe, save) vce(cluster id)
margins , dydx(geo_prox_std) at(time_prox_ld=(0(.1)1) victims_d1=(0 1)) noestimcheck
marginsplot, legend(order(1 "Less than 2 victims" 2 "2 or more victims") pos(6) row(1)) legend(region(lstyle(none))) legend(symxsize(6) forcesize) legend(size(small)) title("Panel b", pos(12) size(medsmall)) yline(0, lcolor(black) lwidth(medthick) lpattern(dash)) ///
xtitle("Time Proximity", height(5)) ytitle("Marginal Effect of Exposure on Britishness (cont.)", size(medsmall)) yscale(titlegap(*+10)) ///
xlabel(0(.1)1, nogrid) ylabel(-0.020(.010).050, nogrid) ///
plot1opts(msize(medsmall) mcolor(midblue) lcolor(midblue)) ci1opts(lwidth(medium) lcolor(midblue)) ///
plot2opts(msize(medsmall) mcolor(midgreen) lcolor(midgreen)) ci2opts(lwidth(medium) lcolor(midgreen)) ///
scheme(s1color) graphregion(color(white)) bgcolor(white) ///
name(Fig_time_prox_victims_cont, replace)
}

grc1leg Fig_time_prox_victims_DV Fig_time_prox_victims_cont, name("row1", replace)
*graph export "$output/Figure_byvictims_Britishness.pdf", replace

*erase Fig_time_prox_victims_DV.gph 
*erase Fig_time_prox_victims_cont.gph

**** Figure 4B: By perpetrator identity

quietly{

reghdfe britishness5 c.geo_prox_std##c.time_prox_ld##i.perpetrator_cat3 $controls if sample1==1, absorb(id attack_code wave##week_fe, save) vce(cluster id)
margins , dydx(geo_prox_std) at(time_prox_ld=(0(.1)1) perpetrator_cat3=1) at(time_prox_ld=(0(.1)1) perpetrator_cat3=2) at(time_prox_ld=(0(.1)1) perpetrator_cat3=3) noestimcheck
marginsplot, legend(order(1 "Islamic" 2 "Far-right" 3 "Other") pos(6) row(1)) legend(region(lstyle(none))) legend(symxsize(6) forcesize) legend(size(small)) title("Panel c", pos(12) size(medsmall)) yline(0, lcolor(black) lwidth(medthick) lpattern(dash)) ///
xtitle("Time Proximity", height(5)) ytitle("Marginal Effect of Exposure on Britishness (DV)", size(medsmall)) yscale(titlegap(*+10)) ///
xlabel(0(.1)1, nogrid) ylabel(-0.020(.010).050, nogrid) ///
plot1opts(msize(medsmall) mcolor(midgreen) lcolor(midgreen)) ci1opts(lwidth(medium) lcolor(midgreen)) ///
plot2opts(msize(medsmall) mcolor(midblue) lcolor(midblue)) ci2opts(lwidth(medium) lcolor(midblue)) ///
plot3opts(msize(medsmall) mcolor(brown) lcolor(brown)) ci3opts(lwidth(medium) lcolor(brown)) ///
scheme(s1color) graphregion(color(white)) bgcolor(white) ///
name(Fig_time_prox_perpetrator_DV, replace)
 
reghdfe britishness c.geo_prox_std##c.time_prox_ld##i.perpetrator_cat3 $controls if sample1==1, absorb(id attack_code wave##week_fe, save) vce(cluster id)
margins , dydx(geo_prox_std) at(time_prox_ld=(0(.1)1) perpetrator_cat3=1) at(time_prox_ld=(0(.1)1) perpetrator_cat3=2) at(time_prox_ld=(0(.1)1) perpetrator_cat3=3) noestimcheck
marginsplot, legend(order(1 "Islamic" 2 "Far-right" 3 "Other") pos(6) row(1)) legend(region(lstyle(none))) legend(symxsize(6) forcesize) legend(size(small)) title("Panel d", pos(12) size(medsmall)) yline(0, lcolor(black) lwidth(medthick) lpattern(dash)) ///
xtitle("Time Proximity", height(5)) ytitle("Marginal Effect of Exposure on Britishness (cont.)", size(medsmall)) yscale(titlegap(*+10)) ///
xlabel(0(.1)1, nogrid) ylabel(-0.020(.010).050, nogrid) ///
plot1opts(msize(medsmall) mcolor(midgreen) lcolor(midgreen)) ci1opts(lwidth(medium) lcolor(midgreen)) ///
plot2opts(msize(medsmall) mcolor(midblue) lcolor(midblue)) ci2opts(lwidth(medium) lcolor(midblue)) ///
plot3opts(msize(medsmall) mcolor(brown) lcolor(brown)) ci3opts(lwidth(medium) lcolor(brown)) ///
scheme(s1color) graphregion(color(white)) bgcolor(white) ///
name(Fig_time_prox_perpetrator_cont, replace)

}

grc1leg Fig_time_prox_perpetrator_DV Fig_time_prox_perpetrator_cont, name("row2", replace)
*graph export "$output/Figure_byperpetrator_Britishness.pdf", replace

*erase Fig_time_prox_perpetrator_DV.gph 
*erase Fig_time_prox_perpetrator_cont.gph

gr combine row1 row2, row(2) col(1) ysize(8)
gr export "$output/Figure_4.pdf", replace
gr export "$output/Figure_4.eps", replace



**** Figure 5: By media coverage

quietly{

reghdfe britishness5 c.geo_prox_std##c.time_prox_ld##i.media3 $controls if sample1==1, absorb(id attack_code wave##week_fe, save) vce(cluster id)
margins , dydx(geo_prox_std) at(time_prox_ld=(0(.1)1) media3=(0 1)) noestimcheck
marginsplot, legend(order(1 "Low media" 2 "High media") pos(6) row(1)) legend(region(lstyle(none))) legend(symxsize(6) forcesize)legend(size(small)) title("Panel a", pos(12) size(medsmall)) yline(0, lcolor(black) lwidth(medthick) lpattern(dash)) ///
xtitle("Time Proximity", height(5)) ytitle("Marginal Effect of Exposure on Britishness (DV)", size(medsmall)) yscale(titlegap(*+10)) ///
xlabel(0(.1)1, nogrid) ylabel(-0.020(.010).050, nogrid) ///
plot1opts(msize(medsmall) mcolor(midblue) lcolor(midblue)) ci1opts(lwidth(medium) lcolor(midblue)) ///
plot2opts(msize(medsmall) mcolor(midgreen) lcolor(midgreen)) ci2opts(lwidth(medium) lcolor(midgreen)) ///
scheme(s1color) graphregion(color(white)) bgcolor(white) ///
name(Fig_time_prox_media_DV, replace)

reghdfe britishness c.geo_prox_std##c.time_prox_ld##i.media3 $controls if sample1==1, absorb(id attack_code wave##week_fe, save) vce(cluster id)
margins , dydx(geo_prox_std) at(time_prox_ld=(0(.1)1) media3=(0 1)) noestimcheck
marginsplot, legend(order(1 "Low media" 2 "High media") pos(6) row(1)) legend(region(lstyle(none))) legend(symxsize(6) forcesize)legend(size(small)) title("Panel b", pos(12) size(medsmall)) yline(0, lcolor(black) lwidth(medthick) lpattern(dash)) ///
xtitle("Time Proximity", height(5)) ytitle("Marginal Effect of Exposure on Britishness (cont.)", size(medsmall)) yscale(titlegap(*+10)) ///
xlabel(0(.1)1, nogrid) ylabel(-0.020(.010).050, nogrid) ///
plot1opts(msize(medsmall) mcolor(midblue) lcolor(midblue)) ci1opts(lwidth(medium) lcolor(midblue)) ///
plot2opts(msize(medsmall) mcolor(midgreen) lcolor(midgreen)) ci2opts(lwidth(medium) lcolor(midgreen)) ///
scheme(s1color) graphregion(color(white)) bgcolor(white) ///
name(Fig_time_prox_media_cont, replace)
 
}

grc1leg Fig_time_prox_media_DV Fig_time_prox_media_cont, name("row3", replace)
gr export "$output/Figure_5.pdf", replace
gr export "$output/Figure_5.eps", replace









********************************************************************************
*** Table 6: Terrorism exposure and Britishness: Closest-attack-between-waves strategy
********************************************************************************

est clear
{	
		
eststo: reghdfe britishness5 c.geo_prox_std##c.time_prox_ld if sample1==1 & closest_attack==1, absorb(id attack_code, save) vce(cluster id)
		estadd local individual "X", replace	
		estadd local attack "X", replace
		estadd local ww "", replace
		estadd local controls "", replace
		
eststo: reghdfe britishness5 c.geo_prox_std##c.time_prox_ld if sample1==1 & closest_attack==1, absorb(id attack_code wave##week_fe, save) vce(cluster id)
		estadd local individual "X", replace	
		estadd local attack "X", replace
		estadd local ww "X", replace
		estadd local controls "", replace
		
eststo: reghdfe britishness5 c.geo_prox_std##c.time_prox_ld $controls if sample1==1 & closest_attack==1, absorb(id attack_code wave##week_fe, save) vce(cluster id)
		estadd local individual "X", replace	
		estadd local attack "X", replace
		estadd local ww "X", replace
		estadd local controls "X", replace


eststo: reghdfe britishness c.geo_prox_std##c.time_prox_ld if sample1==1 & closest_attack==1, absorb(id attack_code, save) vce(cluster id)
		estadd local individual "X", replace	
		estadd local attack "X", replace
		estadd local ww "", replace
		estadd local controls "", replace
		
eststo: reghdfe britishness c.geo_prox_std##c.time_prox_ld if sample1==1 & closest_attack==1, absorb(id attack_code wave##week_fe, save) vce(cluster id)
		estadd local individual "X", replace	
		estadd local attack "X", replace
		estadd local ww "X", replace
		estadd local controls "", replace
		
eststo: reghdfe britishness c.geo_prox_std##c.time_prox_ld $controls if sample1==1 & closest_attack==1, absorb(id attack_code wave##week_fe, save) vce(cluster id)
		estadd local individual "X", replace	
		estadd local attack "X", replace
		estadd local ww "X", replace
		estadd local controls "X", replace
		

esttab est* using "$output/Table_6.csv", star(* .1 ** .05 *** .01) se b(3) r2 ///
keep(geo_prox_std time_prox_ld c.geo_prox_std#c.time_prox_ld) ///
order(geo_prox_std time_prox_ld c.geo_prox_std#c.time_prox_ld) ///
varl(geo_prox_std "Exposure" time_prox_ld "Time prox." c.geo_prox_std#c.time_prox_ld "Exposure $\times$ Time prox.") ///
s(individual attack ww controls r2 N_clust N, ///
label("Individual FEs" "Attack FEs" "Wave $\times$ Week FEs" "Controls" "R-squared" "No. of individuals" "No. of observations" ) /// 
fmt(3 3 3 3 %9.3f %9.0f %9.0f)) ///
replace csv nonotes
est clear
}









********************************************************************************
**** Figure 6: Marginal effect of exposure on Britishness: Closest-attack-between-waves strategy
********************************************************************************

quietly{

reghdfe britishness5 c.geo_prox_std##c.time_prox_ld $controls if sample1==1 & closest_attack==1, absorb(id attack_code wave##week_fe, save) vce(cluster id)
margins, dydx(geo_prox_std) at(time_prox_ld=(0(.05)1)) noestimcheck
marginsplot, legend(pos(6) row(1)) yline(0, lcolor(black) lwidth(medthick) lpattern(dash)) ///
title("") xtitle("Time Proximity", height(5)) ytitle("Marginal Effect of Exposure on Britishness (DV)", size(medsmall)) yscale(titlegap(*+10)) ///
addplot(histogram time_prox_ld if e(sample), start(0) width(.1) legend(off) below fcolor(none) lcolor(gs10) ///
yaxis(2) yscale(off axis(2)) yscale(range(-0.020 0.060) axis(1)) ylabel(-0.020(.010).060, nogrid axis(1)) ///
scheme(s1color) graphregion(color(white)) bgcolor(white) ///
xlabel(-0(.1)1, nogrid)) ///
plot1opts(msize(medsmall) mcolor(black) lcolor(black)) ci1opts(lwidth(medium) lcolor(black)) ///
scheme(s1color) name(Fig_time_prox_ld_DV, replace)


reghdfe britishness c.geo_prox_std##c.time_prox_ld $controls if sample1==1 & closest_attack==1, absorb(id attack_code wave##week_fe, save) vce(cluster id)
margins, dydx(geo_prox_std) at(time_prox_ld=(0(.05)1)) noestimcheck
marginsplot, legend(pos(6) row(1)) yline(0, lcolor(black) lwidth(medthick) lpattern(dash)) ///
title("") xtitle("Time Proximity", height(5)) ytitle("Marginal Effect of Exposure on Britishness (cont.)", size(medsmall)) yscale(titlegap(*+10)) ///
addplot(histogram time_prox_ld if e(sample), start(0) width(.1) legend(off) below fcolor(none) lcolor(gs10) ///
yaxis(2) yscale(off axis(2)) yscale(range(-0.020 0.060) axis(1)) ylabel(-0.020(.010).060, nogrid axis(1)) ///
scheme(s1color) graphregion(color(white)) bgcolor(white) ///
xlabel(-0(.1)1, nogrid)) ///
plot1opts(msize(medsmall) mcolor(black) lcolor(black)) ci1opts(lwidth(medium) lcolor(black)) ///
scheme(s1color) name(Fig_time_prox_ld_cont, replace)
}

gr combine Fig_time_prox_ld_DV Fig_time_prox_ld_cont
graph export "$output/Figure_6.pdf", replace
graph export "$output/Figure_6.eps", replace















